<template>
  <!-- 业务审批 -->
  <CommonTitle titleName="上报请示决策会议名"></CommonTitle>
  <div class="box">
    <el-form
      :inline="true"
      label-width="160"
      :model="formInline"
      :rules="rules"
      ref="formRef"
      class="demo-form-inline"
    >
      <el-row>
        <el-col :span="8"
          ><el-form-item label="关联项目集">
            <el-input
              v-model="formInline.projectSetName"
              disabled
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目名称">
            <el-input
              v-model="formInline.projectName"
              disabled
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目编号">
            <el-input v-model="formInline.projectId" disabled placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目分类">
            <el-input
              v-model="formInline.projectType"
              disabled
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="业务单元">
            <el-input
              v-model="formInline.businessUnitName"
              disabled
              placeholder=""
            />

          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="计划实施时间范围">
            <el-date-picker
              v-model="formInline.predictStartTime"
              type="daterange"
              disabled
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目位置">
            <el-input disabled v-model="formInline.projectRegionName" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目详细地址">
            <el-input disabled v-model="formInline.projectStreetName" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="拟计划总投额">
            <el-input disabled v-model="formInline.projectAmount" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目类型">
            <el-select
              v-model="formInline.projectCategory"
              clearable
              disabled
              placeholder="项目类型"
              @change="streerTypeChange"
            >
              <el-option value="1" label="公司自建"></el-option>
              <el-option value="2" label="政府投资"></el-option>
              <el-option value="3" label="代建项目"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目立项部门">
            <el-input disabled v-model="formInline.projectDepartment" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目负责人">
            <el-input disabled v-model="formInline.departmentUserName" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目编码">
            <el-input disabled v-model="formInline.projectCode" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工作细项名称">
            <el-input disabled v-model="formInline.itemName" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="会议名称" prop="meetingName">
            <el-input
              :disabled="state.disabled"
              v-model="formInline.meetingName"
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
        <!-- 申请原因 -->
          <el-form-item label="决策意见" prop="applyReason">
            <el-input
              :disabled="state.disabled"
              type="textarea"
              v-model="formInline.applyReason"
              placeholder=""
            />
          </el-form-item>
        </el-col>

<!--        <p v-if="state.disabled">审批结果</p>
        <el-col :span="24" v-if="state.disabled">
          <el-form-item label="审批单编号">
            <el-input
              disabled
              v-model="formInline.flowId"
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="state.disabled">
          <el-form-item label="审批状态">
            <el-select disabled
              v-model="formInline.examineStatus"
              placeholder="">
              <el-option value="1" label="审核中">
              </el-option>
              <el-option value="2" label="审核通过">
              </el-option>
              <el-option value="3" label="审核驳回">
              </el-option>

            </el-select>
            </el-form-item>
        </el-col>
        <el-col :span="24" v-if="state.disabled">
          <el-form-item label="查看审批流程">
            <el-button type="primary" @click="openHandler(formInline.routeUrl)" class="button_edit">查看审批流程</el-button>
          </el-form-item>
        </el-col>-->
        <el-col :span="24" v-if="!state.disabled" >
          <el-button @click="submit" type="primary" class="button_view">保存</el-button>
          <el-button type="primary" @click="goback" class="button_cancel2"> 取消 </el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script setup>
import { businessApi, projectConfigApi, department } from '@/api/project'

import { ref, reactive, onBeforeMount, onMounted } from 'vue'
import {
  ElDialog,
  ElForm,
  ElDatePicker,
  ElFormItem,
  ElRow,
  ElCol,
  ElMessage,
  ElSwitch
} from 'element-plus'
import CommonTitle from '@/components/CommonTitle.vue'
import FileUpload from '@/components/FileUpload.vue'
import { useRouter, useRoute } from 'vue-router'
import { getURLhandler } from '@/views/constructionProjectManage/static/utools.js'

let router = useRouter()
let route = useRoute()
const formInline = reactive({
  files: [],

  meetingName: '',
  applyReason: ''
})
const state = reactive({
  projectTaskId: '',
  departmentOptions: [],
  disabled: false,
  projectId: '',
  user: '',
  list: [
    {
      value: '1',
      label: '综合管理部'
    },
    {
      value: '2',
      label: '财务金融部'
    },
    {
      value: '3',
      label: '纪检监察部'
    },
    {
      value: '4',
      label: '开发建设部'
    },
    {
      value: '5',
      label: '投资发展部'
    },
    {
      value: '6',
      label: '招标合约部'
    },
    {
      value: '7',
      label: '数字科技部'
    },
    {
      value: '8',
      label: '设计部'
    },
    {
      value: '9',
      label: '文体事业部'
    },
    {
      value: '10',
      label: '养老事业部'
    },
    {
      value: '11',
      label: '邻里中心事业部'
    },
    {
      value: '12',
      label: '社区商业事业部'
    },
    {
      value: '13',
      label: '社区商业事业二部'
    },
    {
      value: '14',
      label: '文创传媒公司'
    },
    {
      value: '15',
      label: '体育公司'
    },
    {
      value: '16',
      label: '佳医医学检验实验室'
    },
    {
      value: '17',
      label: '领创公司'
    },
    {
      value: '18',
      label: '托育公司'
    },
    {
      value: '19',
      label: '医疗公司'
    },
    {
      value: '20',
      label: '领川置业公司'
    }
  ]
})
const rules = {
  applyReason: [
    { required: true, message: '申请原因不能为空', trigger: 'blur' }
  ],
  meetingName: [
    { required: true, message: '会议名称不能为空', trigger: 'blur' }
  ]
}

const goback = () => {
  router.go(-1)
}
const openHandler=(url)=>{
  window.open(url)
}
const formRef = ref(null)
const submit = () => {
  formRef.value.validate(async (valid, fields) => {
    if (valid) {

      let obj={}
      obj.meetingName = formInline.meetingName
      ;(obj.applyReason = formInline.applyReason),
        (obj.taskId = state.projectTaskId),
        (obj.itemId = state.itemId),
        (obj.projectId = state.projectId)

      await projectConfigApi.bfProjectApprovalTaskAddTask(obj).then((res) => {
        if (res.code == '200') {
          ElMessage.success('操作成功')
          router.go(-1)
        }
      })
    }
  })
}

onBeforeMount(() => {
  state.projectTaskId = getURLhandler(route.path).projectTaskId
  state.projectId = getURLhandler(route.path).projectId
  state.itemId = getURLhandler(route.path).itemId
  state.disabled = +getURLhandler(route.path).isLook
})

onMounted(() => {
  projectConfigApi
    .bfProjectApprovalTaskFormView({
      taskId: state.projectTaskId,
      itemId: state.itemId,
      projectId: state.projectId
    })
    .then((res) => {
      if (res.code == '200') {
        for (const key in res.data) {
          if (Object.hasOwnProperty.call(res.data, key)) {
            if (key == 'predictStartTime') {
              formInline[key] = [res.data[key], res.data['predictEndTime']]
              continue
            }
            if (key == 'files') {
              formInline[key] = res.data[key] || []
              continue
            }
            formInline[key] = res.data[key]
          }
        }
      }
    })
})
</script>

<style lang="scss" scoped>
.el-form-item,
.el-select {
  width: 100%;
}
.box {
  border-radius: 10px;
  border: 1px solid #e3e7f1;
  padding: 34px 90px;
}
</style>
